package com.zhoux.api.io.io;

import java.io.*;

/**
 * @author taoyi
 * @version 1.0
 * @date 2021/3/26 11:26
 *
 * 本类用于测试 用文件流完成文件的复制操作
 *
 *
 */
public class Test_1 {

    public static void copyFile(File file, File file2){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(file);
            fos = new FileOutputStream(file2);
            int len;
            byte[] data = new byte[8*1204];
            while ((len=fis.read(data))!=-1) {
                fos.write(data, 0, len);
            }
            System.out.println("复制成功~");
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
        File file = new File(".\\src\\main\\java\\com\\zhoux\\file\\11.gif");
        File file2 = new File(".\\src\\main\\java\\com\\zhoux\\file\\44.gif");
        copyFile(file,file2);
    }
}
